package com.changfeng.controller;

import com.changfeng.bean.dto.vo.CityListVO;
import com.changfeng.exception.ChangFengException;
import com.changfeng.exception.ChangFengExceptionEnum;
import com.changfeng.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/city")
public class CityController {
    @Autowired
    private CityService cityService;

    @GetMapping("/findByProvinceId")
    public List<CityListVO> findByProvinceId (Integer provinceId) {
        if (provinceId == null) {
            throw new ChangFengException(ChangFengExceptionEnum.PARAM_EXCEPTION);
        }
        return cityService.findByProvinceId(provinceId);
    }
}
